#导入模块
from flask_sqlalchemy import SQLAlchemy
import pymysql
from flask import Flask, render_template,session
import warnings

warnings.filterwarnings('ignore')
#创建flask对象
app = Flask(__name__)

#配置flask配置对象中键：SQLALCHEMY_DATABASE_URI

app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:root@127.0.0.1/first?charset=utf8mb4"

#配置flask配置对象中键：SQLALCHEMY_COMMIT_TEARDOWN,设置为True,应用会自动在每次请求结束后提交数据库中变动

app.config['SQLALCHEMY_COMMIT_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True


db = SQLAlchemy(app)


class User(db.Model):
    __tablename__ = 'db'
    __table_args__ = {
        'mysql_charset': 'utf8mb4'
    }
    id = db.Column(primary_key=True)
    name = db.Column()

aa=User.query.all()
print(aa)
for a in aa:
    print(a.id,a.name)

filters = {
     User.name =='3',
     User.id >0
}
bb=User.query.filter(*filters).first()
print(bb.id)

cc=User.query.filter(*filters).all()
print(cc)

ee=User.query.filter(User.name==2).all()
print(ee)
#print(User.query.get(name = 1 ))

#获取SQLAlchemy实例对象，接下来就可以使用对象调用数据




if __name__ == '__main__':
    app.run()
